﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeManageService
{
    public static class Reporter
    {
        /* GetAllFinishPlan()//获取当前用户总共完成任务的数量
         * GetScore()//获取当前用户已获得的分数
         * GetUsedScore()//获取当前用户已经消耗的分数
         * GetAllFinishWish()//获取当前用户所有完成的愿望
         * GetFinishPlanByTime
         * GetScoreByTime
         * GetUsedScoreByTime
         * GetFinishWishByTime
         */

        public static int GetAllFinishPlan()//获取当前用户总共完成任务的数量
        {
            var query = TurnoverManager.flow.Where(f => f.ScoreChange > 0);
            return query.Count();
        }

        public static int GetScore()//获取当前用户已获得的分数
        {
            int sum = 0;
            var query = TurnoverManager.flow.Where(f => f.ScoreChange > 0);
            foreach (Turnover t in query)
            {
                sum += t.ScoreChange;
            }
            return sum;
        }

        public static int GetUsedScore()//获取当前用户已经消耗的分数
        {
            int sum = 0;
            var query = TurnoverManager.flow.Where(f => f.ScoreChange < 0);
            foreach (Turnover t in query)
            {
                sum += t.ScoreChange;
            }
            return -sum;
        }

        public static int GetAllFinishWish()//获取当前用户所有完成的愿望
        {
            var query = TurnoverManager.flow.Where(f => f.ScoreChange < 0);
            return query.Count();
        }

        public static int GetFinishPlanByTime(DateTime StartTime,DateTime EndTime)//获取指定时间段内的完成任务数量
        {
            var query = TurnoverManager.flow.Where(f => f.Time >= StartTime && f.Time < EndTime && f.ScoreChange>0);
            return query.Count();
        }

        public static int GetScoreByTime(DateTime StartTime,DateTime EndTime)//获取指定时间段内的分数
        {
            int sum = 0;
            var query = TurnoverManager.flow.Where(f => f.ScoreChange > 0 && f.Time >= StartTime && f.Time < EndTime);
            foreach (Turnover t in query)
            {
                sum += t.ScoreChange;
            }
            return sum;
        }

        public static int GetUsedScoreByTime(DateTime StartTime,DateTime EndTime)//获取指定时间段内的使用分数
        {
            int sum = 0;
            var query = TurnoverManager.flow.Where(f => f.ScoreChange < 0&&f.Time >= StartTime && f.Time < EndTime);
            foreach (Turnover t in query)
            {
                sum += t.ScoreChange;
            }
            return -sum;
        }

        public static int GetFinishWishByTime(DateTime StartTime, DateTime EndTime)//获取当前用户所有完成的愿望
        {
            var query = TurnoverManager.flow.Where(f => f.ScoreChange < 0 && f.Time >= StartTime && f.Time < EndTime);
            return query.Count();
        }

        public static int GetUnfinishPlanByTime(DateTime StartTime, DateTime EndTime)
        {
            var query = PlanManager.plans.Where(p => p.PState == 2 && p.EndTime >= StartTime && p.EndTime < EndTime);
            return query.Count();
        }
    }
}
